#!/usr/bin/ruby

QS_PATH = "questions.dat"
EXAM_PATH = "exam.txt"

qs = nil
File.open(QS_PATH,"r") do |f|
  qs = Marshal.load(f.read)
end

raise "ERR : qs is nil" unless qs

f_exam = File.open(EXAM_PATH,"r")
as = f_exam.readlines.select do |line|
  line =~ /^选择:\[\d+\]:\(/
end

s = 0
reg = /^选择:\[(\d+)\]:\(\s*(.?)\s*\)/i
as.map do |line|
  m = reg.match(line)
  idx,a = m[1].to_i,m[2]
  s += qs[idx][4] if qs[idx][3] == a
end

puts s
f_exam.close
#puts as
